/*
 * @Description: 
 * @Author: TzzzT
 * @Date: 2022-03-12 11:19:06
 * @LastEditTime: 2022-11-29 04:34:30
 * @LastEditors: TzzzT
 */
#ifndef _MY_BLE_H
#define _MY_BLE_H


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "esp_bt_defs.h"

enum
{
    IDX_RCS_SVC,
    IDX_CHAR_CLI_TO_SER,
    IDX_CHAR_VAL_CLI_TO_SER,
    IDX_CHAR_SER_TO_CLI,
    IDX_CHAR_VAL_SER_TO_CLI,
    IDX_CHAR_CFG_SER_TO_CLI,
    RCS_SERV_IDX_NB,
};

#define PROFILE_NUM                 1
#define PROFILE_APP_IDX             0
#define ESP_APP_ID                  0x0
#define SAMPLE_DEVICE_NAME          "RCS-SERVER"
#define SVC_INST_ID                 0

/* The max length of characteristic value. When the GATT client performs a write or prepare write operation,
*  the data length must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX. 
*/
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 500
#define PREPARE_BUF_MAX_SIZE        1024
#define CHAR_DECLARATION_SIZE       (sizeof(uint8_t))

#define ADV_CONFIG_FLAG             (1 << 0)
#define SCAN_RSP_CONFIG_FLAG        (1 << 1)


typedef void(*new_cli_connect_cb_t)(esp_bd_addr_t);
typedef void(*cli_disconnect_cb_t)(esp_bd_addr_t);
typedef void(*cli_write_cb_t)(esp_bd_addr_t, uint8_t* , uint8_t);

typedef struct server_func_s{
    new_cli_connect_cb_t cli_conn_cb;   
    cli_disconnect_cb_t  cli_disconn_cb;
    cli_write_cb_t cli_write_cb;
}server_func_t;

server_func_t* get_server_func_p(void);

void ble_server_init(void);
void ble_server_close(void);
bool is_server_advertising(void);
void stop_server_advertising(void);
esp_err_t set_adv_device_name(uint8_t* adv_dev_name,uint8_t name_len);
esp_err_t notify_client(uint8_t *value, uint16_t value_len);
esp_err_t close_server(void);
#endif  // _MY_BLE_H